package com.sld.concrete.algorithm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.sld.concrete.algorithm.domain.RecPlateAlgorithm;
import com.sld.concrete.algorithm.service.IRecPlateAlgorithmService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 算法系数Controller
 * 
 * @author topviewers
 * @date 2022-04-15
 */
@Controller
@RequestMapping("/device/algorithm")
public class RecPlateAlgorithmController extends BaseController
{
    private String prefix = "device/algorithm";

    @Autowired
    private IRecPlateAlgorithmService recPlateAlgorithmService;

    @RequiresPermissions("device:algorithm:view")
    @GetMapping()
    public String algorithm()
    {
        return prefix + "/algorithm";
    }

    /**
     * 查询算法系数列表
     */
    @RequiresPermissions("device:algorithm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecPlateAlgorithm recPlateAlgorithm)
    {
        startPage();
        List<RecPlateAlgorithm> list = recPlateAlgorithmService.selectRecPlateAlgorithmList(recPlateAlgorithm);
        return getDataTable(list);
    }

    /**
     * 导出算法系数列表
     */
    @RequiresPermissions("device:algorithm:export")
    @Log(title = "算法系数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecPlateAlgorithm recPlateAlgorithm)
    {
        List<RecPlateAlgorithm> list = recPlateAlgorithmService.selectRecPlateAlgorithmList(recPlateAlgorithm);
        ExcelUtil<RecPlateAlgorithm> util = new ExcelUtil<RecPlateAlgorithm>(RecPlateAlgorithm.class);
        return util.exportExcel(list, "算法系数数据");
    }

    /**
     * 新增算法系数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存算法系数
     */
    @RequiresPermissions("device:algorithm:add")
    @Log(title = "算法系数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecPlateAlgorithm recPlateAlgorithm)
    {
        int result = recPlateAlgorithmService.insertRecPlateAlgorithm(recPlateAlgorithm);
        if (result < 0) {
            return AjaxResult.error("车牌号有重复！");
        }
        return toAjax(result);
    }

    /**
     * 修改算法系数
     */
    @RequiresPermissions("device:algorithm:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RecPlateAlgorithm recPlateAlgorithm = recPlateAlgorithmService.selectRecPlateAlgorithmById(id);
        mmap.put("recPlateAlgorithm", recPlateAlgorithm);
        return prefix + "/edit";
    }

    /**
     * 修改保存算法系数
     */
    @RequiresPermissions("device:algorithm:edit")
    @Log(title = "算法系数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecPlateAlgorithm recPlateAlgorithm)
    {
        return toAjax(recPlateAlgorithmService.updateRecPlateAlgorithm(recPlateAlgorithm));
    }

    /**
     * 删除算法系数
     */
    @RequiresPermissions("device:algorithm:remove")
    @Log(title = "算法系数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recPlateAlgorithmService.deleteRecPlateAlgorithmByIds(ids));
    }
}
